package com.definity.toolkit.web.taglib;

import javax.servlet.jsp.JspException;

public class ButtonTag extends ComponentFormTag {

	private static final long serialVersionUID = -5546070384766281607L;

	private Boolean defaultAction;
	private String popup;
	private String action;
	
	public ButtonTag() {
		defaultAction = false;
	}
	
	@Override
	protected String getComponentName() {
		return "button";
	}
	
	public void setDefaultAction(Boolean defaultAction) {
		this.defaultAction = defaultAction;
	}
	
	public void setPopup(String popup) {
		this.popup = popup;
	}
	
	public void setAction(String action) {
		this.action = action;
	}

	@Override
	protected int doStartTag(FormTag formTag, StringBuilder html) throws JspException {
		String type = "button";
		if (defaultAction)
			type = "submit";
		
		String changeAction = "";
		if (action != null)
			changeAction = "changeAction";
		
		html.append("<input type=\"" + type + "\"");
		html.append(" id=\"");
		html.append(getLabel());
		html.append("\"");
		if (defaultAction)
			html.append(createStyleClass("btn", "action_button", changeAction));
		else
			html.append(createStyleClass("btn"));
		if (popup != null && popup.length() != 0)
			html.append(" popup=\"" + popup + "\"");
		
		if (action != null)
			html.append(" actionUrl=\"" + action + "\"");
		
		html.append(" value=\"");
		html.append(i18n().tl("button." + getLabel()));
		html.append("\" />");
		
		return SKIP_BODY;
	}
	
	@Override
	protected int doEndTag(FormTag formTag, StringBuilder html) throws JspException {
		return EVAL_PAGE;
	}
	
	@Override
	protected String createStartTag(String name, String id, Object value) throws JspException {
		return null;
	}
	
	@Override
	protected String createEndTag(String name, String id, Object value) throws JspException {
		return null;
	}
	
}
